<?php

namespace Controller\Passport;

use \Controller\Base as Base;

class Login extends Base {

    public $mustLogin = false;

    public function actionIndex() {
        if ($this->isPost()) {
            $this->doLogin();
        }
        $this->display();
    }

    public function doLogin() {
        $account = $this->postParam('account');
        $password = $this->postParam('password');
        if (!$account) {
            $this->addWarningMsg('请填写账号');
            return;
        }
        if (!$password) {
            $this->addWarningMsg('请填写密码');
            return;
        }
        $accountInfo = \Business\Account::instance()->getByAccount($account);
        if (!$accountInfo) {
            $this->addWarningMsg('账号不存在');
            return;
        }
        $password = $this->encryptionPassword($password);
        if ($password != $accountInfo['Password']) {
            $this->addWarningMsg('密码错误');
            return;
        }
        $accountId = $accountInfo['Id'];
        \Util\Account::setAccountIdToCookie($accountId);
        \Util\Comm::redirect('/');
    }

}
